package com.glela.task.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.glela.task.domain.TaskOrderParams;
import com.glela.task.domain.TaskOrderStatus;
import com.glela.task.domain.TaskOrderType;
import com.glela.task.mapper.TaskOrderMapper;
import com.glela.task.model.TaskOrder;
import com.glela.task.service.TaskOrderService;

@Service
public class TaskOrderServiceImpl implements TaskOrderService {
	@Autowired
	private TaskOrderMapper taskOrderMapper;

	@Override
	public List<TaskOrder> queryAll(TaskOrderParams taskOrderParams) {
		return taskOrderMapper.selectAll(taskOrderParams);
	}

	@Override
	public boolean addTask(TaskOrder addTaskOrder) {
		if (addTaskOrder == null) {
			throw new NullPointerException();
		}
		if (addTaskOrder.getoObjId() == null || addTaskOrder.getoObjId() < 0) {
			throw new NullPointerException();
		}
		if (addTaskOrder.getTaskType() == null || addTaskOrder.getTaskType() < 1) {
			throw new NullPointerException();
		}
		return taskOrderMapper.insertSelective(addTaskOrder) == 1;
	}

	@Override
	public boolean modifStatus(long id, TaskOrderStatus newStatus, int nowStatus, String memo) {
		if (id < 0 || newStatus == null || nowStatus < 0) {
			throw new NullPointerException();
		}
		return taskOrderMapper.updateStatusById(id, newStatus.getTaskStatus(), nowStatus, memo);
	}

	@Override
	public boolean modifStatus(long oObjId, TaskOrderType taskOrderType, TaskOrderStatus newStatus, int nowStatus, String memo) {
		if (oObjId < 0 || taskOrderType == null || newStatus == null || nowStatus < 0) {
			throw new NullPointerException();
		}
		return taskOrderMapper.updateStatusByObjIdAndType(oObjId, taskOrderType.getTaskType(), newStatus.getTaskStatus(), nowStatus, memo);
	}

}
